package com.docker.jy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.docker.common.annotation.Anonymous;
import com.docker.jy.domain.dao.DailyTotalDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.docker.common.annotation.Log;
import com.docker.common.core.controller.BaseController;
import com.docker.common.core.domain.AjaxResult;
import com.docker.common.enums.BusinessType;
import com.docker.jy.domain.DoctorOrder;
import com.docker.jy.service.IDoctorOrderService;
import com.docker.common.utils.poi.ExcelUtil;
import com.docker.common.core.page.TableDataInfo;

/**
 * 订单收费Controller
 * 
 * @author ruoyi
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/jy/money")
public class DoctorOrderController extends BaseController
{
    @Autowired
    private IDoctorOrderService doctorOrderService;

    /**
     * 查询订单收费列表
     */
    @PreAuthorize("@ss.hasPermi('jy:money:list')")
    @GetMapping("/list")
    public TableDataInfo list(DoctorOrder doctorOrder)
    {
        startPage();
        List<DoctorOrder> list = doctorOrderService.selectDoctorOrderList(doctorOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单收费列表
     */
    @PreAuthorize("@ss.hasPermi('jy:money:export')")
    @Log(title = "订单收费", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DoctorOrder doctorOrder)
    {
        List<DoctorOrder> list = doctorOrderService.selectDoctorOrderList(doctorOrder);
        ExcelUtil<DoctorOrder> util = new ExcelUtil<DoctorOrder>(DoctorOrder.class);
        util.exportExcel(response, list, "订单收费数据");
    }

    /**
     * 获取订单收费详细信息
     */
    @PreAuthorize("@ss.hasPermi('jy:money:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(doctorOrderService.selectDoctorOrderById(id));
    }

    /**
     * 新增订单收费
     */
    @PreAuthorize("@ss.hasPermi('jy:money:add')")
    @Log(title = "订单收费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorOrder doctorOrder)
    {
        return toAjax(doctorOrderService.insertDoctorOrder(doctorOrder));
    }

    /**
     * 修改订单收费
     */
    @PreAuthorize("@ss.hasPermi('jy:money:edit')")
    @Log(title = "订单收费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorOrder doctorOrder)
    {
        return toAjax(doctorOrderService.updateDoctorOrder(doctorOrder));
    }

    /**
     * 删除订单收费
     */
    @PreAuthorize("@ss.hasPermi('jy:money:remove')")
    @Log(title = "订单收费", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(doctorOrderService.deleteDoctorOrderByIds(ids));
    }

    //根据每一天的日期查询所有患者的总金额,最后在前端调用这个方法,将日期传入,返回一个list集合,集合中存放的是每一天的日期和对应的总金额，然后在前端页面中使用echarts中的折线图展示出来
    @Anonymous
    @GetMapping("/dailyTotal")
    public AjaxResult getDailyTotalAmount() {
        List<DailyTotalDTO> dailyTotals = doctorOrderService.selectDoctorOrderByDate(null);
        return AjaxResult.success(dailyTotals);
    }
}
